/************************************************************************

								Heroes IV
					  Copyright 2000, The 3DO Company

	------------------------------------------------------------------
  							 script_adjust_population.cpp

	$Header: /heroes4/script_adjust_population.cpp $

	$NoKeywords: $

 ************************************************************************/

// kill the 255+ character identifier warning.  Templates tend to exceed that easily.
#include "precompiled.h"
#pragma warning( disable: 4786 )

#include "script_adjust_population.h"

#include "sized_int_types.h"
#include "streambuf_operators.h"
#include "town.h"
#include "town_building.h"

// --------------------------------------------------------------------------
// t_script_adjust_population members
// --------------------------------------------------------------------------

// --------------------------------------------------------------------------
// --------------------------------------------------------------------------
bool t_script_adjust_population::read(
	std::streambuf &	stream,
	int					version )
{
	if (!t_abstract_script_action::read( stream, version ))
		return false;

	m_dwelling_number = get< t_uint8 >( stream );
	m_adjustment = get< t_uint16 >( stream );

	return true;
}

// --------------------------------------------------------------------------
// --------------------------------------------------------------------------
bool t_script_adjust_population::read_from_map(
	std::streambuf &	stream,
	int					format_version )
{
	m_dwelling_number = get< t_uint8 >( stream );
	if ( m_dwelling_number < 0 || m_dwelling_number > k_dwelling_count )
		return false;

	m_adjustment = get< t_uint16 >( stream ) * m_direction;

	return true;
}

// --------------------------------------------------------------------------
// --------------------------------------------------------------------------
bool t_script_adjust_population::write( std::streambuf & stream ) const
{
	if (!t_abstract_script_action::write( stream ))
		return false;
	
	put< t_uint8 >( stream, m_dwelling_number );
	put< t_uint16 >( stream, m_adjustment );

	return true;
}

// --------------------------------------------------------------------------
// --------------------------------------------------------------------------
void t_script_adjust_population::execute(t_script_context_hero const& context) const
{
	assert(false);
}

void t_script_adjust_population::execute(t_script_context_town const& context) const
{
	if (context.town == NULL) {
		assert(false);
		return;
	}
	context.town->adjust_population(get_dwelling_number(), get_adjustment());
}

void t_script_adjust_population::execute(t_script_context_object const& context) const
{
	assert(false);
}

void t_script_adjust_population::execute(t_script_context_army const& context) const
{
	assert(false);
}

void t_script_adjust_population::execute(t_script_context_global const& context) const
{
	assert(false);
}
